#ifndef EPOLL_IMPL_H
#define EPOLL_IMPL_H
#include <sys/epoll.h>
#include <queue>
#include <string>
using namespace std;

class Asynch_handle;
class Srv_Asynch_Man;
class Epoll_Impl
{
public:
    Epoll_Impl(Srv_Asynch_Man *);
public:
    void epoll_Init(const char *pAddr,int nPort);

    virtual ~Epoll_Impl(void);

    bool send_passive_prc(int sockfd, string & strbuf);

    bool send_active_prc(int sockfd,  string & strbuf);

    void read_passive_prc(int sockfd, string & strbuf);

    void destroy_connection_prc(int sockfd);
private:
    int  setnonblocking(int sockfd);

    void mod_fd(int fd, uint32_t fig);
    void add_fd(int fd, uint32_t fig);
    void del_fd(int fd);

    virtual int svc();

    virtual int close();

    void read_prc(epoll_event &socket);

    void connect_prc();
    //
    static void * svc_run( void *apParam);//
private:
    int g_epollFd;

    int m_listenFd;
private:
    Asynch_handle  *m_pAsynch_handle;
    Srv_Asynch_Man *m_pAsynch_Man;
    int             h_threadId;
    //std::queue<int> h_threads;
    int fd_pipe[2];
};

#endif // EPOLL_IMPL_H
